// pages/calendar/calendar.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    dayList: [],
    dataNewList: { name: ['女生节', '劳动节', '端午节', '四周年纪念日', '七夕情人节', '中秋节', '然然生日', '国庆', '路路生日', '元旦'], date: ['2023-03-07', '2023-05-01', '2023-06-13', '2023-06-22', '2023-08-22', '2023-09-29', '2023-09-30', '2023-10-01', '2023-12-03', '2024-01-01'], img: ['../../images/jr/j1.jpg', '../../images/jr/j2.jpg', '../../images/jr/j14.jpg', '../../images/jr/j3.jpg', '../../images/jr/j4.jpg', '../../images/jr/qixi.jpg', '../../images/jr/j5.jpg', '../../images/jr/j11.jpg', '../../images/jr/j12.jpg', '../../images/jr/j13.jpg', '../../images/jr/hsj.jpg', '../../images/jr/j9.jpg', '../../images/jr/j10.jpg'], color: ['#fbe0e5', '#ccd6ef', '#ded4f5', '#f1cce0', '#daced0', '#f7f6f6', '#c5fbe7', '#ff607b', '#f8fdd1', '#cc8c97', '#ffeec0', '#d8c0ff', '#ffcec0'], }
  },
  getDate(list) {
    var date = new Date();
    var seperator1 = "-";
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
      month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
      strDate = "0" + strDate;
    }
    var currentdate = year + seperator1 + month + seperator1 + strDate;
    let dayList = []
    let sname=this.data.dataNewList.name
    let img=this.data.dataNewList.img
    let color=this.data.dataNewList.color
    list.map((item, i) => {
      let d = {}
      d.day = parseInt((new Date(item).getTime() - new Date(currentdate).getTime()) / (1000 * 60 * 60 * 24))
      d.date = item
      d.name = sname[i]
      d.img = img[i]
      d.color = color[i]
      dayList.push(d)
    })

    let min
    let Arr = dayList
    let Arr0 = []
    for (var i = 0; i < Arr.length; i++) {
      for (var j = i; j < Arr.length; j++) {
        // console.log(Arr[j].day)
        if (Arr[i].day >= 0) {
          if (Arr[i].day > Arr[j].day) {
            min = Arr[j];
            Arr[j] = Arr[i];
            Arr[i] = min;
          }
        }
      }
    }
    let falg = 0
    Arr.map((item, i) => {
      if (item.day < 0) {
        falg++
        Arr0.push(item)
      }
    })
    Arr.splice(0, falg)
    let min1
    Arr0.map((item, i) => {
      for (var c = i; c < Arr0.length; c++) {
        if (Arr0[i].day < Arr0[c].day) {
          min1 = Arr0[c];
          Arr0[c] = Arr0[i];
          Arr0[i] = min1;
        }
      }
    })
    Arr0.map((item, i) => {
      item.color = '#403e3e'
    })
    // console.log(Arr0)
    Arr = Arr.concat(...Arr0)
    this.setData({
      dayList: Arr
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let list = this.data.dataNewList.date
    // '女生节',  '劳动节', '端午节', '四周年纪念日', '七夕情人节', '中秋节', '然然生日', '国庆', '路路生日'，'元旦'

    this.getDate(list)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})